package model

import (
	"database/sql"
	"gorm.io/gorm"
)

type RoutePath struct {
	BaseModel
	RouteID                 int64  `json:"route_id"`
	RoutePathName           string `json:"route_path_name"`
	RouteBackendService     string `json:"route_backend_service"`
	RouteBackendServicePort int32  `json:"route_backend_service_port"`
}

// 在同一个事务中更新数据
func (p *RoutePath) AfterDelete(tx *gorm.DB) (err error) {
	if p.DeletedAt.Valid {
		tx.Exec("UPDATE route_path SET is_deleted = @is_deleted where route_id = @route_id",
			sql.Named("is_deleted", true), sql.Named("route_id", p.RouteID))
	}
	return
}
